package com.kou.service.impl;

import com.kou.dao.CartDao;
import com.kou.dao.CartDaoImpl;
import com.kou.dao.GoodsDao;
import com.kou.dao.GoodsDaoImpl;
import com.kou.pojo.Cart;
import com.kou.pojo.Goods;
import com.kou.service.CartService;

import java.util.List;

/**
 * @author SteinY
 * @create 2022-03-25 15:49
 * @description:
 */
public class CartServiceImpl implements CartService {
    CartDao cartDao = new CartDaoImpl();
    GoodsDao goodsDao = new GoodsDaoImpl();
    @Override
    public void create(String pid, int uid) {
//
//        private int cid; //购物车主键id
//        private int uid; //用户id
//        private int pid; //商品id
//        private Goods goods;
//        private int num = 0;  //购车商品数量
//        private int money; //购物车小计
        Goods goods = goodsDao.findGoodsById(pid);

        cartDao.create(pid,uid,goods.getPrice());


    }

    @Override
    public List<Cart> findCarts(String uid) {
        return cartDao.findCarts(uid);
    }

    @Override
    public void delete(String cid) {
        cartDao.delete(cid);
    }

    @Override
    public void update(String cid, String cnum, String price) {
        cartDao.update(cid,cnum,price);
    }

    @Override
    public void clear(String uid) {
        cartDao.clear(uid);
    }

    @Override
    public Cart findCart(String pid, int uid) {
        return cartDao.findCart(pid,uid);
    }
}
